<template>
  <div>
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
  <el-form-item label="检验名称" prop="name">
    <el-input v-model="form.name"></el-input>
  </el-form-item>
  <el-form-item label="检验费用" prop="code">
    <el-input v-model="form.fee"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="save()">保存数据</el-button>
  </el-form-item>
  
      </el-form>
  </div>
</template>

<script>
export default {
    name: 'InspectItemEdit',
    props:[
        'editid'
    ],
    data(){
        return {
            form: {
                id:this.editid,
                name:'',
                fee: '',
            },
            isupdate : false,
            url: '/inspect-item/add',
            rules:{
                name: [
                    {required: true,message:'检验项目名不能为空',trigger: 'blur'},
                    {min:1,max:50,message:'检验项目名长度在1-100之间',trigger:'blur'}
                    ],
                fee: [
                    {required: true,message:'检验费用不能为空',trigger: 'blur'}
                    ]
            }
            
        }
    },
    methods: {
        save()
        {//验证信息是否合法输入
            this.$refs['form'].validate((valid) => {
          if (valid) {
              
            this.axios.post(this.url,response => {
                this.$emit('update:show',false)
                this.$emit('getdata')
            },
            this.form)
          } 
        })
        }
    },
    created(){
        
        if(this.editid)
        {
            this.isupdate = true
            this.url = '/inspect-item/update'
            this.axios.get('/inspect-item/getById',response => {
                this.form=response.obj
                delete this.form['createtime']
            },{id:this.editid})
        }
        
    }
}
</script>

<style>

</style>